import xbot
import xbot_visual
from . import package
from .package import variables as glv
import time

def main(args):
    if args is None:
        loop_item2 = ""
        zhanghao = ""
        config_url = ""
        result = []
        now_datetime = ""
    else:
        loop_item2 = args.get("loop_item2", "")
        zhanghao = args.get("zhanghao", "")
        config_url = args.get("config_url", "")
        result = args.get("result", [])
        now_datetime = args.get("now_datetime", "")
    try:
        # programing.snippet
        # programing.variable
        # programing.variable
        xbot_visual.programing.sleep(random_number=False, seconds="3", start_number="1", stop_number="5", _block=("处理邮箱确认及返回数据", 4, "等待"))
        xbot_visual.programing.log(type="info", text="开始执行并发子流程", _block=("处理邮箱确认及返回数据", 5, "打印日志"))
        from datetime import datetime
        current_datetime = datetime.now()
        # 格式化日期和时间，只显示到分钟
        now_datetime = current_datetime.strftime('%Y-%m-%d %H:%M')
        print(now_datetime)
        xbot_visual.programing.log(type="info", text=lambda: now_datetime, _block=("处理邮箱确认及返回数据", 7, "打印日志"))
        loop_index = -1
        while True:
            loop_index += 1
            import re
            
            
            def queren(IMEI_ID, email):
                from datetime import datetime
                current_datetime = datetime.now()
                # 格式化日期和时间，只显示到分钟
                formatted_datetime = current_datetime.strftime('%Y-%m-%d %H:%M')
                print(formatted_datetime)
            
                obj = re.compile(
                    "Make sure you \n(?P<url>.*?)\nconfirm your request  within 24 hours or we'll have to cancel it.\n", re.DOTALL)
                while True:
                    proxy_url = 'http://127.0.0.1:7897'  # 假设代理服务器的地址和端口是127.0.0.1和3128
                    proxies = {
            
                    }
            
                    import requests
                    try:
                        url = "https://api.rurl.vip/mail/get"
            
                        params = {
                            "user": "318258885",
                            "token": "342b29f569914a77dbdc2923b5dbacb1cd12eeb1",
                            "receiver": str(email),  # 用邮箱账号即可收取信息,
                            "subject": "Heads up! You have 24 hours to confirm your unlock request.",
                            "type": "HTML",
                            "sender": "att-online.services@account.att-mail.com",
                            "time":formatted_datetime
                        }
            
                        result = requests.get(url, params=params, proxies=proxies)
            
                        config_url = str(obj.findall(result.text)[0]).strip('').strip("\n")
                        print(config_url)
                        config_url = config_url
            
                        return config_url
                        break
                    except Exception as e:
                        print(e)
                        print("未获取到链接")
            
            config_url = queren(loop_item2, zhanghao)
            
            if xbot_visual.workflow.test(operand1=config_url, operator="not empty value", operand2="", operator_options="{\"values\":\"None,Empty,Blank\"}", _block=("处理邮箱确认及返回数据", 10, "IF 条件")):
                xbot_visual.programing.log(type="info", text=config_url, _block=("处理邮箱确认及返回数据", 11, "打印日志"))
                break
            #endif
        #endloop
        web_page3 = xbot_visual.web.create(web_type="chrome", value=config_url, silent_running=True, wait_load_completed=True, load_timeout="20", stop_load_if_load_timeout="handleExcept", chrome_file_name=None, edge_file_name=None, ie_file_name=None, bro360_file_name=None, firefox_file_name=None, arguments=None, _block=("处理邮箱确认及返回数据", 15, "打开网页"))
        xbot_visual.programing.log(type="info", text="确认邮件完毕", _block=("处理邮箱确认及返回数据", 16, "打印日志"))
        xbot_visual.programing.sleep(random_number=False, seconds="2", start_number="1", stop_number="5", _block=("处理邮箱确认及返回数据", 17, "等待"))
        xbot_visual.web.browser.close(operation="close_specified", browser=web_page3, web_type="cef", task_kill=False, _block=("处理邮箱确认及返回数据", 18, "关闭网页"))
        web_page3 = xbot_visual.web.create(web_type="chrome", value=config_url, silent_running=True, wait_load_completed=True, load_timeout="20", stop_load_if_load_timeout="handleExcept", chrome_file_name=None, edge_file_name=None, ie_file_name=None, bro360_file_name=None, firefox_file_name=None, arguments=None, _block=("处理邮箱确认及返回数据", 19, "打开网页"))
        xbot_visual.programing.log(type="info", text="确认邮件完毕", _block=("处理邮箱确认及返回数据", 20, "打印日志"))
        xbot_visual.web.browser.close(operation="close_specified", browser=web_page3, web_type="cef", task_kill=False, _block=("处理邮箱确认及返回数据", 21, "关闭网页"))
        loop_index = -1
        while True:
            loop_index += 1
            import re
            
            import requests
            
            proxy_url = 'http://127.0.0.1:7897'
            proxies = {
            
            }
            
            import requests
            import time
            import random
            from hashlib import md5
            
            
            def fanyi(english):
                headers = {
                    'Cookie': 'OUTFOX_SEARCH_USER_ID=-690213934@10.108.162.139; OUTFOX_SEARCH_USER_ID_NCOO=1273672853.5782404; fanyi-ad-id=308216; fanyi-ad-closed=1; ___rl__test__cookies=1659506664755',
                    'Host': 'fanyi.youdao.com',
                    'Origin': 'https://fanyi.youdao.com',
                    'Referer': 'https://fanyi.youdao.com/',
                    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
                }
                key = english
                # input("请输入你要翻译的单词：")
                lts = str(int(time.time() * 100))
                salt = lts + str(random.randint(0, 9))
                sign_data = 'fanyideskweb' + key + salt + 'Ygy_4c=r#e#4EX^NUGUc5'
                sign = md5(sign_data.encode()).hexdigest()
                data = {
                    'i': key,
                    'from': 'AUTO',
                    'to': 'AUTO',
                    'smartresult': 'dict',
                    'client': 'fanyideskweb',
                    # 时间戳  1970  秒
                    'salt': salt,
                    # 加密
                    'sign': sign,
                    # 时间戳
                    'lts': lts,
                    # 加密的数据
                    'bv': 'f0819a82107e6150005e75ef5fddcc3b',
                    'doctype': 'json',
                    'version': '2.1',
                    'keyfrom': 'fanyi.web',
                    'action': 'FY_BY_REALTlME',
                }
            
                # 获取到资源地址
                url = 'https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule'
                response = requests.post(url, headers=headers, data=data, proxies=proxies)
                # print(response.text)
                print(response.json()["translateResult"][0][0]["tgt"])
                return response.json()["translateResult"][0][0]["tgt"]
            
            
            
            
            
            def put_order(car_id,content_text):
                car_list=car_id.split("|")
                print(car_list)
                if content_text:
                    headers = {
                        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
                        "Accept-Language": "zh-CN,zh;q=0.9",
                        "Cache-Control": "no-cache",
                        "Connection": "keep-alive",
                        "Content-Type": "application/x-www-form-urlencoded",
                        "Origin": "http://xgkj.163wx.cn",
                        "Pragma": "no-cache",
                        "Referer": "http://xgkj.163wx.cn/admincp/code.php?id="+car_list[0],
                        "Upgrade-Insecure-Requests": "1",
                        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0"
                    }
                    cookies = {
                        "intro_show": "1",
                        "PHPSESSID": "ls8f72ofr3sbdgp540l2g62iae",
                        "SITE_LANGUAGE": "cn"
                    }
                    url = "http://xgkj.163wx.cn/admincp/code.php"
                    params = {
                        "id":car_list[0]
                    }
                    data = {
                        "id": car_list[0],
                        "userId": car_list[1],
                        # "codeCr": car_list[2],
                        "imei": car_list[3],
                        "packageId": car_list[5],
                        "pckTitle": "US ATT黑白名单查询+ 低概率解锁 快解 （是否解锁都要收费）",
                        "updateType": "4",
                        "codeStatusId": "2",
                        "other": "",
                        "codeSentToOtherServer": "0",
                        "OrderIdFromServer": "",
                        "txtCode": "<p><font _msthash=\"299\" _mstmutation=\"1\" _msttexthash=\"104635284\">"+str(content_text)+"</font></p>\r\n",
                        "txtComments": ""
                    }
                    response = requests.post(url, headers=headers, cookies=cookies, params=params, data=data, verify=False)
            
            #这里定义了提交订单的函数
            
            
            #放入响应体即可
            def pipei(result):
            
                obj5 = re.compile("""<pre>(?P<zhuti>.*?)Hi Cher""", re.DOTALL)
                if "Let's get your device unlocked" in result:
                    print("Unlocked (已解锁)")
                    result_t = "Unlocked (已解锁)"
                    return result_t
                elif "You've tried to unlock this device too many times. Wai t 30 days and then" in result:
                    print("解锁失败，提交解锁请求过多，已被ATT官方限制30天")
                    result_t = "解锁失败，提交解锁请求过多，已被ATT官方限制30天"
                    return result_t
                elif "You have a past due balance on your account" in result:
                    print("解锁失败，此设备处于逾期状态")
                    result_t = "解锁失败，此设备处于逾期状态"
                    return result_t
                elif "We can't unlock this device until the former owner removes it from their AT&T account." in result:
                    print("解锁失败，此设备活跃在其他账户中")
                    result_t = "解锁失败，此设备活跃在其他账户中"
                    return result_t
                elif "在购买后60天之前，我们无法解锁您的设备" in result:
                    print("解锁失败，设备活跃未满60天或者激活未满60天")
                    result_t = "解锁失败，设备活跃未满60天或者激活未满60天"
                    return result_t
                elif "在购买后60天之前" in result:
                    print("解锁失败，设备活跃未满60天或者激活未满60天")
                    result_t = "解锁失败，设备活跃未满60天或者激活未满60天"
                    return result_t
                elif "We can't unlock your device today" in result:
                    print("解锁失败，此设备已被ATT官方限制30天（建议30天后在提交）")
                    result_t = "解锁失败，此设备已被ATT官方限制30天（建议30天后在提交）"
                    return result_t
                elif "今天我们不能解锁你的设备" in result:
                    print("解锁失败，此设备已被ATT官方限制30天（建议30天后在提交）")
                    result_t = "解锁失败，此设备已被ATT官方限制30天（建议30天后在提交）"
                    return result_t
                elif "We're missing some info" in result or "我们缺少一些信息" in result:
                    print("解锁失败，此设备处于不活跃状态")
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
                elif "Make sure your device meets our eligibility" in result or "确保您的设备符合我们的资格要求" in result:
                    print("解锁失败，此设备处于不活跃状态")
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
                elif "设备丢失或被盗" in result:
                    print("解锁失败，此设备在ATT官方处于黑名单状态")
                    result_t = "解锁失败，此设备在ATT官方处于黑名单状态"
                    return result_t
                elif "You've tried to unlock this device too many times. Wai t 30 days and then" in result:
            
                    print("解锁失败，提交解锁请求过多，已被ATT官方限制30天")
            
                    result_t = "解锁失败，提交解锁请求过多，已被ATT官方限制30天"
                    return result_t
            
                elif "You have a past due balance on your account" in result:
            
                    print("解锁失败，此设备处于逾期状态")
            
                    result_t = "解锁失败，此设备处于逾期状态"
                    return result_t
            
                elif "We can't unlock this device until the former owner removes it from their AT&T account." in result:
            
                    print("解锁失败，此设备活跃在其他账户中")
            
                    result_t = "解锁失败，此设备活跃在其他账户中"
                    return result_t
                elif "This device was reported lost or stolen" in result:
            
                    print("解锁失败，此设备在ATT官方处于黑名单状态")
            
                    result_t = "解锁失败，此设备在ATT官方处于黑名单状态"
                    return result_t
            
                elif "We're missing some info" in result:
            
                    print("解锁失败，此设备处于不活跃状态")
            
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
                elif "我们缺少一些信息" in result:
            
                    print("解锁失败，此设备处于不活跃状态")
            
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
                elif "确保您的设备符合我们的资格要求" in result:
            
                    print("解锁失败，此设备处于不活跃状态")
            
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
            
                elif "The account owner needs to remove the device from their account first. For assistance" in result:
                    print("解锁失败，此设备活跃在其他账户中")
                    result_t = "解锁失败，此设备活跃在其他账户中"
                    return result_t
            
                elif "For assistance, call 800.331.0500." in result:
                    print("解锁失败，此设备活跃在其他账户中")
                    result_t = "解锁失败，此设备活跃在其他账户中"
                    return result_t
                elif "We can only unlock devices that are part of the AT&T network." in result:
                    print("您的设备不是AT&T运营商，请检查运营商。")
                    result_t = "您的设备不是AT&T运营商，请检查运营商。"
                    return result_t
                elif "Make sure you have the correct IMEI number and then" in result:
                    print("您的设备不是AT&T运营商，请检查运营商。")
                    result_t = "您的设备不是AT&T运营商，请检查运营商。"
                    return result_t
            
                elif "我们已经在处理此设备的解锁请求" in result:
            
                    print("您的解锁请求，已存在ATT系统中")
            
                    result_t = "您的解锁请求，已存在ATT系统中"
                    return result_t
                else:
                    print(result)
                    p1 = obj5.finditer(result)
                    for i in p1:
                        # print(i.group('zhuti'))
                        res = i.group('zhuti')
                        second_line = res.strip().strip('').strip(' ').split('\n')
                        non_blank_lines = [line for line in second_line if line.strip()]
                        # print(non_blank_lines)
                        # 剔除后的结果
                        print(non_blank_lines[1])
                        non_blank_lines[1] = fanyi(non_blank_lines[1])
                        print(non_blank_lines[1])
                        result_t = non_blank_lines[1]
                        print(result_t)
                        return result_t
            
            
            
            def pipei_text(result):
            
                obj5 = re.compile("""<pre>(?P<zhuti>.*?)Hi Cher""", re.DOTALL)
                if "Let's get your device unlocked" in result:
                    print("Unlocked (已解锁)")
                    result_t = "Unlocked (已解锁)"
                    return result_t
                elif "You've tried to unlock this device too many times. Wai t 30 days and then" in result:
                    print("解锁失败，提交解锁请求过多，已被ATT官方限制30天")
                    result_t = "解锁失败，提交解锁请求过多，已被ATT官方限制30天"
                    return result_t
                elif "The account owner needs to remove the device from their account first. For assistance" in result:
                    print("解锁失败，此设备活跃在其他账户中")
                    result_t = "解锁失败，此设备活跃在其他账户中"
                    return result_t
                elif "For assistance, call 800.331.0500." in result:
                    print("解锁失败，此设备活跃在其他账户中")
                    result_t = "解锁失败，此设备活跃在其他账户中"
                    return result_t
                elif "We can only unlock devices that are part of the AT&T network." in result:
                    print("您的设备不是AT&T运营商，请检查运营商。")
                    result_t = "您的设备不是AT&T运营商，请检查运营商。"
                    return result_t
                elif "Make sure you have the correct IMEI number and then" in result:
                    print("您的设备不是AT&T运营商，请检查运营商。")
                    result_t = "您的设备不是AT&T运营商，请检查运营商。"
                    return result_t
            
                elif "我们已经在处理此设备的解锁请求" in result:
            
                    print("您的解锁请求，已存在ATT系统中")
            
                    result_t = "您的解锁请求，已存在ATT系统中"
                    return result_t
                elif "You have a past due balance on your account" in result:
                    print("解锁失败，此设备处于逾期状态")
                    result_t = "解锁失败，此设备处于逾期状态"
                    return result_t
                elif "We can't unlock this device until the former owner removes it from their AT&T account." in result:
                    print("解锁失败，此设备活跃在其他账户中")
                    result_t = "解锁失败，此设备活跃在其他账户中"
                    return result_t
                elif "在购买后60天之前，我们无法解锁您的设备" in result:
                    print("解锁失败，设备活跃未满60天或者激活未满60天")
                    result_t = "解锁失败，设备活跃未满60天或者激活未满60天"
                    return result_t
                elif "在购买后60天之前" in result:
                    print("解锁失败，设备活跃未满60天或者激活未满60天")
                    result_t = "解锁失败，设备活跃未满60天或者激活未满60天"
                    return result_t
            
                elif "我们缺少一些信息" in result:
            
                    print("解锁失败，此设备处于不活跃状态")
            
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
                elif "确保您的设备符合我们的资格要求" in result:
            
                    print("解锁失败，此设备处于不活跃状态")
            
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
                elif "今天我们不能解锁你的设备" in result:
                    print("解锁失败，此设备已被ATT官方限制30天（建议30天后在提交）")
                    result_t = "解锁失败，此设备已被ATT官方限制30天（建议30天后在提交）"
                    return result_t
                elif "We're missing some info" in result or "我们缺少一些信息" in result:
                    print("解锁失败，此设备处于不活跃状态")
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
                elif "Make sure your device meets our eligibility" in result or "确保您的设备符合我们的资格要求" in result:
                    print("解锁失败，此设备处于不活跃状态")
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
                elif "设备丢失或被盗" in result:
                    print("解锁失败，此设备在ATT官方处于黑名单状态")
                    result_t = "解锁失败，此设备在ATT官方处于黑名单状态"
                    return result_t
                elif "You've tried to unlock this device too many times. Wai t 30 days and then" in result:
            
                    print("解锁失败，提交解锁请求过多，已被ATT官方限制30天")
            
                    result_t = "解锁失败，提交解锁请求过多，已被ATT官方限制30天"
                    return result_t
            
                elif "You have a past due balance on your account" in result:
            
                    print("解锁失败，此设备处于逾期状态")
            
                    result_t = "解锁失败，此设备处于逾期状态"
                    return result_t
            
                elif "We can't unlock this device until the former owner removes it from their AT&T account." in result:
            
                    print("解锁失败，此设备活跃在其他账户中")
            
                    result_t = "解锁失败，此设备活跃在其他账户中"
                    return result_t
                elif "This device was reported lost or stolen" in result:
            
                    print("解锁失败，此设备在ATT官方处于黑名单状态")
            
                    result_t = "解锁失败，此设备在ATT官方处于黑名单状态"
                    return result_t
            
                elif "We're missing some info" in result:
            
                    print("解锁失败，此设备处于不活跃状态")
            
                    result_t = "解锁失败，此设备处于不活跃状态"
                    return result_t
            
                else:
                    result_t=result
                    return result_t
            
            
            
            
            
            
            def huoqujieguo(IMEI_ID, email):
                global result_t
                result_t=""
                try:
                    proxy_url = 'http://127.0.0.1:7897'  # 假设代理服务器的地址和端口是127.0.0.1和3128
                    proxies = {
            
                        }
            
                    url = "https://api.rurl.vip/mail/get"
            
                    params = {
                            "user": "318258885",
                            "token": "342b29f569914a77dbdc2923b5dbacb1cd12eeb1",
                            "receiver": str(email),  # 用邮箱账号即可收取信息,
                            "subject": "Heads up! We approved your unlock request.",
                            #"subject": "Heads up! We can't process your unlock request. ",
                            #"subject":"Heads up! We can't approve your unlock request.",
                            "type": "html",
                            "time":now_datetime,
                            "sender": "att-online.services@account.att-mail.com"
                    }
            
                    result = requests.get(url, params=params, proxies=proxies)
                    print(result.text)
                        # json_data=result.json()
                    obj5 = re.compile("""<pre>(?P<zhuti>.*?)Hi Cher""", re.DOTALL)
            
                    print(IMEI_ID)
                    # print(result.text)
                    # if "Let's get your device unlocked" in result.text:
                    #     print("Unlocked (已解锁)")
                    #     result_t = "Unlocked (已解锁)"
                    #
                    # elif "You've tried to unlock this device too many times. Wai t 30 days and then" in result.text:
                    #
                    #     print("解锁失败，提交解锁请求过多，已被ATT官方限制30天")
                    #
                    #     result_t = "解锁失败，提交解锁请求过多，已被ATT官方限制30天"
                    #
                    # elif "You have a past due balance on your account" in result.text:
                    #
                    #     print("解锁失败，此设备处于逾期状态")
                    #
                    #     result_t = "解锁失败，此设备处于逾期状态"
                    #
                    # elif "We can't unlock this device until the former owner removes it from their AT&T account." in result.text:
                    #
                    #     print("解锁失败，此设备活跃在其他账户中")
                    #
                    #     result_t = "解锁失败，此设备活跃在其他账户中"
                    # else:
                    #     print(result.text)
                    #     p1 = obj5.finditer(result.text)
                    #     for i in p1:
                    #         # print(i.group('zhuti'))
                    #         res = i.group('zhuti')
                    #         second_line = res.strip().strip('').strip(' ').split('\n')
                    #         non_blank_lines = [line for line in second_line if line.strip()]
                    #         # print(non_blank_lines)
                    #         # 剔除后的结果
                    #         print(non_blank_lines[1])
                    #         non_blank_lines[1]=fanyi(non_blank_lines[1])
                    #         print(non_blank_lines[1])
                    #         result_t = non_blank_lines[1]
                    #         print(result_t)
                    result_t=pipei(result.text)
            
                    print(IMEI_ID, result_t)
                    if result_t:
                        result_t = pipei_text(result_t)
                        # 这里写上传数据到服务器的逻辑
                        if "活跃在" in result_t:
                            result_t = "此设备活跃在其他账户"
                        elif "unlocked" in result_t:
                            result_t = "Unlocked (已解锁)"
                        put_order(IMEI_ID, result_t)
                        print("上传完成")
                        return [IMEI_ID, result_t]
                    else:
                        print("返回值为空")
            
                    # 上传完成则break
                except Exception as e:
                    print(e)
                    print("未收到邮件")
                try:
                    proxy_url = 'http://127.0.0.1:7897'  # 假设代理服务器的地址和端口是127.0.0.1和3128
                    proxies = {
            
                        }
            
                    url = "https://api.rurl.vip/mail/get"
            
                    params = {
                            "user": "318258885",
                            "token": "342b29f569914a77dbdc2923b5dbacb1cd12eeb1",
                            "receiver": str(email),  # 用邮箱账号即可收取信息,
                            #"subject": "Heads up! We approved your unlock request.",
                            #"subject": "Heads up! We can't process your unlock request. ",
                            "subject":"Heads up! We can't approve your unlock request.",
                            "type": "html",
                            "time": now_datetime,
                            "sender": "att-online.services@account.att-mail.com"
                    }
            
                    result = requests.get(url, params=params, proxies=proxies)
                    print(result.text)
                        # json_data=result.json()
                    obj5 = re.compile("""<pre>(?P<zhuti>.*?)Hi Cher""", re.DOTALL)
            
                    print(IMEI_ID)
                    # print(result.text)
                    # if "Let's get your device unlocked" in result.text:
                    #     print("Unlocked (已解锁)")
                    #     result_t = "Unlocked (已解锁)"
                    # elif "You've tried to unlock this device too many times. Wai t 30 days and then" in result.text:
                    #     print("解锁失败，提交解锁请求过多，已被ATT官方限制30天")
                    #     result_t = "解锁失败，提交解锁请求过多，已被ATT官方限制30天"
                    # elif "You have a past due balance on your account" in result.text:
                    #     print("解锁失败，此设备处于逾期状态")
                    #     result_t = "解锁失败，此设备处于逾期状态"
                    # elif "We can't unlock this device until the former owner removes it from their AT&T account." in result.text:
                    #     print("解锁失败，此设备活跃在其他账户中")
                    #     result_t = "解锁失败，此设备活跃在其他账户中"
                    #
                    # else:
                    #     print(result.text)
                    #     p1 = obj5.finditer(result.text)
                    #     for i in p1:
                    #         # print(i.group('zhuti'))
                    #         res = i.group('zhuti')
                    #         second_line = res.strip().strip('').strip(' ').split('\n')
                    #         non_blank_lines = [line for line in second_line if line.strip()]
                    #         # print(non_blank_lines)
                    #         # 剔除后的结果
                    #         print(non_blank_lines[1])
                    #         non_blank_lines[1]=fanyi(non_blank_lines[1])
                    #         print(non_blank_lines[1])
                    #         result_t = non_blank_lines[1]
                    #         print(result_t)
                    result_t = pipei(result.text)
                    print(IMEI_ID, result_t)
                    if result_t:
                        #result_t=pipei_text(result_t)
                        # 这里写上传数据到服务器的逻辑
                        print([IMEI_ID, result_t])
                        put_order(IMEI_ID, result_t)
                        print("上传完成")
                        print([IMEI_ID, result_t])
                        return [IMEI_ID, result_t]
                    else:
                        print("返回值为空")
            
                    # 上传完成则break
                except Exception as e:
                    print(e)
                    print("未收到邮件")
            
                try:
                    proxy_url = 'http://127.0.0.1:7897'  # 假设代理服务器的地址和端口是127.0.0.1和3128
                    proxies = {
            
                        }
            
                    url = "https://api.rurl.vip/mail/get"
            
                    params = {
                            "user": "318258885",
                            "token": "342b29f569914a77dbdc2923b5dbacb1cd12eeb1",
                            "receiver": str(email),  # 用邮箱账号即可收取信息,
                            #"subject": "Heads up! We approved your unlock request.",
                            #"subject":"Heads up! We can't approve your unlock request.",
                            "subject": "Heads up! We can't process your unlock request.",
                            "type": "html",
                            "time": now_datetime,
                            "sender": "att-online.services@account.att-mail.com"
                    }
            
                    result = requests.get(url, params=params, proxies=proxies)
                    print(result.text)
                        # json_data=result.json()
                    obj5 = re.compile("""<pre>(?P<zhuti>.*?)Hi Cher""", re.DOTALL)
            
                    print(IMEI_ID)
                    # print(result.text)
                    # if "Let's get your device unlocked" in result.text:
                    #     print("Unlocked (已解锁)")
                    #     result_t = "Unlocked (已解锁)"
                    # elif "You've tried to unlock this device too many times. Wai t 30 days and then" in result.text:
                    #     print("解锁失败，提交解锁请求过多，已被ATT官方限制30天")
                    #     result_t = "解锁失败，提交解锁请求过多，已被ATT官方限制30天"
                    # elif "You have a past due balance on your account" in result.text:
                    #     print("解锁失败，此设备处于逾期状态")
                    #     result_t = "解锁失败，此设备处于逾期状态"
                    # elif "We can't unlock this device until the former owner removes it from their AT&T account." in result.text:
                    #     print("解锁失败，此设备活跃在其他账户中")
                    #     result_t = "解锁失败，此设备活跃在其他账户中"
                    # elif "在购买后 60 天之前，我们无法解锁您的设备" in result.text:
                    #     print("解锁失败，设备活跃未满60天或者激活未满60天")
                    #     result_t = "解锁失败，设备活跃未满60天或者激活未满60天"
                    # elif "今天我们不能解锁你的设备" in result.text:
                    #     print("解锁失败，此设备已被ATT官方限30天（建议30天后在提交）")
                    #     result_t = "解锁失败，此设备已被ATT官方限30天（建议30天后在提交）"
                    # elif "We're missing some info" in result.text or "我们缺少一些信息" in result.text:
                    #     print("解锁失败，此设备处于不活跃状态")
                    #     result_t = "解锁失败，此设备处于不活跃状态"
                    # elif "Make sure your device meets our eligibility" in result.text or "确保您的设备符合我们的资格要求" in result.text:
                    #     print("解锁失败，此设备处于不活跃状态")
                    #     result_t = "解锁失败，此设备处于不活跃状态"
                    # elif "设备丢失或被盗" in result.text:
                    #     print("解锁失败，此设备在ATT官方处于黑名单状态")
                    #     result_t = "解锁失败，此设备在ATT官方处于黑名单状态"
                    # else:
                    #     print(result.text)
                    #     p1 = obj5.finditer(result.text)
                    #     for i in p1:
                    #         # print(i.group('zhuti'))
                    #         res = i.group('zhuti')
                    #         second_line = res.strip().strip('').strip(' ').split('\n')
                    #         non_blank_lines = [line for line in second_line if line.strip()]
                    #         # print(non_blank_lines)
                    #         # 剔除后的结果
                    #         print(non_blank_lines[1])
                    #         non_blank_lines[1]=fanyi(non_blank_lines[1])
                    #         print(non_blank_lines[1])
                    #         result_t = non_blank_lines[1]
                    #         print(result_t)
                    result_t = pipei(result.text)
            
                    print(IMEI_ID, result_t)
                    if result_t:
                        result_t = pipei_text(result_t)
                        # 这里写上传数据到服务器的逻辑
                        if "活跃在" in result_t:
                            result_t = "此设备活跃在其他账户"
                        elif "unlocked" in result_t:
                            result_t = "Unlocked (已解锁)"
                        put_order(IMEI_ID, result_t)
                        print("上传完成")
                        return [IMEI_ID, result_t]
                    else:
                        print("返回值为空")
            
                    # 上传完成则break
                except Exception as e:
                    print(e)
                    print("未收到邮件")
                try:
                    proxy_url = 'http://127.0.0.1:7897'  # 假设代理服务器的地址和端口是127.0.0.1和3128
                    proxies = {
            
                        }
            
                    url = "https://api.rurl.vip/mail/get"
            
                    params = {
                            "user": "318258885",
                            "token": "342b29f569914a77dbdc2923b5dbacb1cd12eeb1",
                            "receiver": str(email),  # 用邮箱账号即可收取信息,
                            #"subject": "Heads up! We approved your unlock request.",
                            #"subject":"Heads up! We can't approve your unlock request.",
                            "subject": "Heads up! We can't complete your unlock request",
                            "type": "html",
                            "time": now_datetime,
                            #"sender": "att-online.services@account.att-mail.com"
                    }
            
                    result = requests.get(url, params=params, proxies=proxies)
                    print(result.text)
                        # json_data=result.json()
                    obj5 = re.compile("""<pre>(?P<zhuti>.*?)Hi Cher""", re.DOTALL)
            
                    print(IMEI_ID)
                    # print(result.text)
                    # if "Let's get your device unlocked" in result.text:
                    #     print("Unlocked (已解锁)")
                    #     result_t = "Unlocked (已解锁)"
                    # elif "You've tried to unlock this device too many times. Wai t 30 days and then" in result.text:
                    #     print("解锁失败，提交解锁请求过多，已被ATT官方限制30天")
                    #     result_t = "解锁失败，提交解锁请求过多，已被ATT官方限制30天"
                    # elif "You have a past due balance on your account" in result.text:
                    #     print("解锁失败，此设备处于逾期状态")
                    #     result_t = "解锁失败，此设备处于逾期状态"
                    # elif "We can't unlock this device until the former owner removes it from their AT&T account." in result.text:
                    #     print("解锁失败，此设备活跃在其他账户中")
                    #     result_t = "解锁失败，此设备活跃在其他账户中"
                    # elif "在购买后 60 天之前，我们无法解锁您的设备" in result.text:
                    #     print("解锁失败，设备活跃未满60天或者激活未满60天")
                    #     result_t = "解锁失败，设备活跃未满60天或者激活未满60天"
                    # elif "今天我们不能解锁你的设备" in result.text:
                    #     print("解锁失败，此设备已被ATT官方限30天（建议30天后在提交）")
                    #     result_t = "解锁失败，此设备已被ATT官方限30天（建议30天后在提交）"
                    # elif "We're missing some info" in result.text or "我们缺少一些信息" in result.text:
                    #     print("解锁失败，此设备处于不活跃状态")
                    #     result_t = "解锁失败，此设备处于不活跃状态"
                    # elif "Make sure your device meets our eligibility" in result.text or "确保您的设备符合我们的资格要求" in result.text:
                    #     print("解锁失败，此设备处于不活跃状态")
                    #     result_t = "解锁失败，此设备处于不活跃状态"
                    # elif "设备丢失或被盗" in result.text:
                    #     print("解锁失败，此设备在ATT官方处于黑名单状态")
                    #     result_t = "解锁失败，此设备在ATT官方处于黑名单状态"
                    # else:
                    #     print(result.text)
                    #     p1 = obj5.finditer(result.text)
                    #     for i in p1:
                    #         # print(i.group('zhuti'))
                    #         res = i.group('zhuti')
                    #         second_line = res.strip().strip('').strip(' ').split('\n')
                    #         non_blank_lines = [line for line in second_line if line.strip()]
                    #         # print(non_blank_lines)
                    #         # 剔除后的结果
                    #         print(non_blank_lines[1])
                    #         non_blank_lines[1]=fanyi(non_blank_lines[1])
                    #         print(non_blank_lines[1])
                    #         result_t = non_blank_lines[1]
                    #         print(result_t)
                    result_t = pipei(result.text)
            
                    print(IMEI_ID, result_t)
                    if result_t:
                        result_t = pipei_text(result_t)
                        # 这里写上传数据到服务器的逻辑
                        if "活跃在" in result_t:
                            result_t = "此设备活跃在其他账户"
                        elif "unlocked" in result_t:
                            result_t = "Unlocked (已解锁)"
                        put_order(IMEI_ID, result_t)
                        print("上传完成")
                        return [IMEI_ID, result_t]
                    else:
                        print("返回值为空")
            
                    # 上传完成则break
                except Exception as e:
                    print(e)
                    print("未收到邮件")
            
            
            # result = huoqujieguo(loop_item2, zhanghao)
            result = huoqujieguo(loop_item2, zhanghao)
            
            if xbot_visual.workflow.test(operand1=result, operator="not empty value", operand2="", operator_options="{\"values\":\"None,Empty,Blank\"}", _block=("处理邮箱确认及返回数据", 24, "IF 条件")):
                xbot_visual.programing.log(type="info", text=result, _block=("处理邮箱确认及返回数据", 25, "打印日志"))
                break
            #endif
        #endloop
        xbot_visual.programing.log(type="info", text="数据上传完毕", _block=("处理邮箱确认及返回数据", 29, "打印日志"))
        databook_row_count = xbot_visual.programing.databook.get_row_count(_block=("处理邮箱确认及返回数据", 30, "读取数据表格总行数"))
        xbot_visual.programing.databook.write_data_to_workbook(write_range="area", write_way="append", write_column_way="override", row_num=lambda: databook_row_count+1, column_name="5", begin_row_num="1", begin_column_name="", content=result, _block=("处理邮箱确认及返回数据", 31, "写入内容至数据表格"))
        # programing.snippet
        # programing.snippet
    finally:
        pass
